#ifndef _BOARD_CONFIG_H
#define _BOARD_CONFIG_H
#include "os/types.h"   // IWYU pragma: export
#include "gpio.h"


#define SERIAL_NONE       0
#define SERIAL_BOOTLOADER 1

#define CONFIG_REDUCE_STORAGE		1

#define CAN_PIN_MAP_PA11_PA12		1
#define CAN_PIN_MAP_PB8_PB9			2
#define CAN_PIN_MAP_PD0_PD1			3
#define CAN_PIN_MAP_PB12_PB13		4

#ifdef CONFIG_BOARD_ODRIVE
#define CONFIG_SERIAL_TYPE SERIAL_BOOTLOADER
#define CONFIG_BOARD_NAME			"odrive"
#define CONFIG_ADDR_ID              0x4D
#define CONFIG_UART_TX_SIZE 512
#define CONFIG_UART_RX_SIZE 2048
#define CONFIG_IAP_PAGE_SIZE (4*1024)
#include "stm32f405xx.h" // IWYU pragma: export
#include "stm32f4xx_hal.h" // IWYU pragma: export
#include "stm32f4xx_ll_rcc.h" // IWYU pragma: export
#include "stm32f4xx_ll_pwr.h" // IWYU pragma: export
#include "stm32f4xx_ll_system.h" // IWYU pragma: export
#include "stm32f4xx_ll_utils.h" // IWYU pragma: export
#define CONFIG_FLASH_ADDR      FLASH_BASE
#define CONFIG_PART_INFO        (CONFIG_FLASH_ADDR + 0x4000)
#define CONFIG_PART_APP			(CONFIG_FLASH_ADDR + 0x8000)
#define CONFIG_PART_NAME		(CONFIG_FLASH_ADDR + 0x8800)
#define CONFIG_APP_MAX_SIZE     (200 << 10)
#elif defined(CONFIG_BOARD_USB2CAN)
#define CONFIG_SERIAL_TYPE SERIAL_BOOTLOADER
#define CONFIG_BOARD_NAME			"USB2CAN"
#define CONFIG_ADDR_ID              0x0
#define CONFIG_UART_TX_SIZE 512
#define CONFIG_UART_RX_SIZE 1024
#define CONFIG_IAP_PAGE_SIZE (2*1024)
#include "stm32g4xx.h"
#include "stm32g4xx_hal.h"
#include "legacy/stm32_hal_legacy.h"
#include "stm32g4xx_ll_rcc.h" // IWYU pragma: export
#include "stm32g4xx_ll_pwr.h" // IWYU pragma: export
#include "stm32g4xx_ll_system.h" // IWYU pragma: export
#include "stm32g4xx_ll_utils.h" // IWYU pragma: export
#include "stm32g4xx_ll_bus.h"
#define CONFIG_FLASH_ADDR       FLASH_BASE
#define CONFIG_PART_INFO        (CONFIG_FLASH_ADDR + 0x4000)
#define CONFIG_PART_APP			(CONFIG_FLASH_ADDR + 0x5000)
#define CONFIG_PART_NAME		(CONFIG_FLASH_ADDR + 0x5800)
#define CONFIG_APP_MAX_SIZE     (110 << 10)
#endif

#ifndef REG32
#define REG32(addr)                  (*(volatile uint32_t *)(uint32_t)(addr))
#endif
#ifndef REG16
#define REG16(addr)                  (*(volatile uint16_t *)(uint32_t)(addr))
#endif
#ifndef REG8
#define REG8(addr)                   (*(volatile uint8_t *)(uint32_t)(addr))
#endif

#ifndef CONFIG_CAN_PKG_COUNT
#define CONFIG_CAN_PKG_COUNT		8
#endif

#ifndef CONFIG_CAN_TX_FRAMES
#define CONFIG_CAN_TX_FRAMES		30
#endif

#ifndef CONFIG_CAN_RX_FRAMES
#define CONFIG_CAN_RX_FRAMES		60
#endif

#ifndef CONFIG_UART_TX_SIZE
#define CONFIG_UART_TX_SIZE			512
#endif

#ifndef CONFIG_UART_RX_SIZE
#define CONFIG_UART_RX_SIZE			512
#endif
#endif /*_BOARD_CONFIG_H */
